<!--
 * @Author: zhangmengqiong
 * @Date: 2021-04-30 16:46:25
 * @LastEditors: zhangmengqiong
 * @LastEditTime: 2021-04-30 16:58:57
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>g6图表demo</title>
    <script src="https://gw.alipayobjects.com/os/lib/antv/g6/3.7.1/dist/g6.min.js"></script>
  </head>
  <body>
    <div id="mountNode"></div>
    <script>
      // 定义数据源
      const data = {
        // 点集
        nodes: [
          {
            id: 'node1',
            label: '开始',
            x: 100,
            y: 200,
            size: 80,
            labelCfg: {
              position: 'center',
              style: {
                fontSize: 16,
                fill: 'red',
              },
            },
          },
          {
            id: 'node2',
            label: '连接',
            x: 300,
            y: 200,
          },
          {
            id: 'node3',
            label: '结束',
            x: 500,
            y: 200,
          },
          {
            id: 'node4',
            label: '结束4',
            x: 300,
            y: 400,
          },
        ],
        // 边集
        edges: [
          // 表示一条从 node1 节点连接到 node2 节点的边
          {
            source: 'node1',
            target: 'node2',
            label: '连接线1',
          },
          {
            source: 'node2',
            target: 'node3',
            label: '连接线2',
          },
          {
            source: 'node1',
            target: 'node4',
            label: '连接线3',
          },
        ],
      };
      // 创建
      const graph = new G6.Graph({
        container: 'mountNode', // 指定图画布的容器 id，与第 9 行的容器对应
        // 画布宽高
        width: 800,
        height: 500,
        defaultNode: {
          shape: 'circle',
          size: [100],
          color: '#5B8FF9',
          style: {
            fill: '#9EC9FF',
            lineWidth: 3,
          },
          labelCfg: {
            style: {
              fill: 'yellow',
              fontSize: 20,
            },
          },
        },
        defaultEdge: {
          style: {
            stroke: '#e2e2e2',
          },
        },
      });
      // 读取数据
      graph.data(data);
      // 渲染图
      graph.render();
    </script>
  </body>
</html>
